package org.bookie.model.services.impl;

import java.util.List;

import org.bookie.model.Outcome;
import org.bookie.model.Wager;
import org.bookie.model.services.OutcomeDAO;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;


public class HibernateOutcomeDAO extends GenericHibernateDAO<Outcome, Long> implements OutcomeDAO {

	public int countWager(Outcome outcome) {
		List result = getSession().createCriteria(Wager.class)
			.setProjection( Projections.projectionList()
					.add(Projections.countDistinct("id"))
					.add(Projections.groupProperty("outcome")))
			.add(Restrictions.eq("outcome", outcome)).list();
		if(result.isEmpty())return 0;
		Object[] obj = (Object[])result.get(0);
		return ((Number)obj[0]).intValue();
	}

}
